"use client"
import { useState } from 'react';
import {axios} from '../../Global'
import {useRouter } from 'next/navigation'

export default function Home() {
  const router = useRouter()
  const [user,setUser] = useState('a');
  const [password,setPassword] = useState('123as123');
  

  function login(){
    axios({
        method: 'post',
        url: `${process.env.NEXT_PUBLIC_API_URL}/api/users/login`,
        data: {
            user: user,
            password: password,
        }
    }).then(function (response) {
        if(response.data.code){
            localStorage.setItem('token',response.data.data.token);
            router.push('/')
        }
    }).catch(function (error) {
        console.log(error);
    });
  }

  return (
    <div className="about">
        账号：<input value={user} onChange={ e=> setUser(e.target.value)}/>
        密码：<input value={password} onChange={ e=> setPassword(e.target.value)}/>
        <button onClick={login}>登录</button>
    </div>
  );
}